package com.hengpeng.msls.util;

import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.hengpeng.common.configuration.ConfigProvider;
import com.hengpeng.common.configuration.ConfigProviderFactory;
import com.hengpeng.common.constant.Constant;
import com.hengpeng.common.persist.QueryResult;
import com.hengpeng.itfinbase.message.ResponseMessage;
import com.hengpeng.itfinbase.persist.Account;
import com.hengpeng.msls.constants.LSConstants;
import com.hengpeng.msls.domain.LoginUser;
import com.hengpeng.msls.domain.PageInfo;
import com.hengpeng.msls.service.userInfo.UserInfoService;

/**
 * 通用工具类
 * 
 * @author wuhaifei
 * @version 1.0, 2012-5-28
 */
public class CommUtil {
    private final static Log logger = LogFactory.getLog(CommUtil.class);

    private static final String CLIENT_REQUEST_DATETIME_PATTERN = "yyyyMMddHHmmss";

    /**
     * 玩法路径名称
     */
    private static Map<String, String> pathName = new HashMap<String, String>();

    private static ConfigProvider<String> cp;

    /**
     * 获取会员店编号
     * 
     * @param request
     * @return
     */
    public static String getStoreId(HttpServletRequest request) {
        String serverName = request.getServerName();
        String storeId = CommUtil.getProperyValue(serverName);
        return isEmpty(storeId) ? "100" : storeId;
    }

    /**
     * 获取站点名称
     */
    public static String getSiteName(HttpServletRequest request) {
        String serverName = request.getServerName();
        String siteName = CommUtil.getProperyValue("site." + serverName);
        return isEmpty(siteName) ? "开心彩票" : siteName;
    }

    /**
     * 根据玩法英文名称获取投注页面路径
     * 
     * @param gameNameE
     * @return
     */
    public static String getPathName(String gameNameE) {
        if (pathName.get(gameNameE) == null) {
            pathName.put(gameNameE, splicePathName(gameNameE));
        }
        return pathName.get(gameNameE);
    }

    /**
     * 拼接对应玩法页面路径
     * 
     * @param gameNameE
     * @return
     */
    private static String splicePathName(String gameNameE) {
        StringBuffer path = new StringBuffer("lottery_");
        path.append(gameNameE);
        path.append("/buy_");
        path.append(gameNameE);
        return path.toString();
    }

    /**
     * 将List&ltObject&gt封装到Map(key：指定属性，value：对象本身)
     * 
     * @param list
     *            对象集合
     * @param methodName
     *            方法名称，原来获取指定属性值
     * @return 包含实体对象主键和实体对象的map
     */
    public static Map<?, ?> weaveListToMap(List<?> list, String methodName) {
        Map<Object, Object> map = null;
        Class<? extends Object> clazz = null;
        Object value = null;
        Method method = null;
        if (list != null && list.size() > 0) {
            map = new HashMap<Object, Object>();
            for (Object object : list) {
                clazz = object.getClass();
                try {
                    method = clazz.getMethod(methodName);
                    value = method.invoke(object);
                    map.put(value, object);
                } catch (SecurityException e1) {
                    e1.printStackTrace();
                } catch (NoSuchMethodException e1) {
                    e1.printStackTrace();
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                }
            }
        }
        return map;
    }

    /**
     * 拼接分页导航
     * 
     * @param page
     *            分页信息
     * @param size
     *            每页记录数
     * @param gameId
     *            玩法id
     * @param queryDate
     *            查询日期
     * @param dateType
     *            查询日期类型
     * @param request
     *            HttpServletRequest
     * @return
     */
    public static String createPageNavigator(PageInfo pageInfo, int gameId, int queryDate, String dateType,
            HttpServletRequest request) {
        StringBuffer url = new StringBuffer(request.getRequestURI());
        url.append("?size=");
        url.append(pageInfo.getPagesize());
        url.append("&gameId=");
        url.append(gameId);
        url.append("&queryDate=");
        url.append(queryDate);
        url.append("&dateType=");
        url.append(dateType);
        url.append("&");
        return createNavigatorC(pageInfo, url.toString());
    }

    /**
     * 拼接分页导航
     * 
     * @param pageInfo
     *            分页信息
     * @param request
     *            请求信息
     * @param groupIds
     *            新闻分组编号集
     * @return
     */
    public static String createPageNavigator(PageInfo pageInfo, HttpServletRequest request, String groupIds) {
        StringBuffer url = new StringBuffer(request.getRequestURI());
        url.append("?size=");
        url.append(pageInfo.getPagesize());
        if (!isEmpty(groupIds)) {
            url.append("&groupIds=");
            url.append(groupIds);
        }
        url.append("&");
        return createNavigatorC(pageInfo, url.toString());
    }

    /**
     * 拼接分页导航辅助方法
     * 
     * @param page
     * @param url
     * @return
     */
    private static String createNavigatorC(PageInfo page, String url) {
        // 第？页 共？页上一页下一页
        StringBuffer sb = new StringBuffer();
        sb.append("<span>第&nbsp;").append(page.getCurrentpage()).append("&nbsp;页&nbsp;共&nbsp;")
                .append(page.getTotalpage()).append("&nbsp;页&nbsp;共&nbsp;").append(page.getTotalcount())
                .append("&nbsp;条&nbsp;");

        if (page.getCurrentpage() > 1) {
            sb.append("<a href=\"").append(url).append("index=").append(1).append("\">首页</a>&nbsp;");
            sb.append("<a href=\"").append(url).append("index=").append(page.getCurrentpage() - 1)
                    .append("\">上一页</a>&nbsp;");
        }

        if (page.getCurrentpage() < page.getTotalpage()) {
            sb.append("<a href=\"").append(url).append("index=").append(page.getCurrentpage() + 1)
                    .append("\">下一页</a>&nbsp;");
            sb.append("<a href=\"").append(url).append("index=").append(page.getTotalpage()).append("\">末页</a>&nbsp;");
        }
        sb.append("</span>");
        logger.debug(sb.toString());
        return sb.toString();
    }

    /**
     * 判断给定的返回是否处理成功
     * 
     * @param result
     * @return
     */
    public static boolean isSuccess(QueryResult<?> result) {
        if (result != null) {
            if (Contants.SUCCEES.getValue().equals(result.getCode())) {
                return true;
            } else {
                logger.info(result.getMessage());
            }
        } else {
            logger.info("返回信息为空..");
        }
        return false;
    }

    /**
     * 判断给定的返回是否处理成功
     * 
     * @param planRespones
     * @return
     */
    public static boolean isSuccess(ResponseMessage response) {
        if (response != null && Contants.SUCCEES.getValue().equals(response.getRespCode())) {
            return true;
        }
        return false;
    }

    /**
     * 将字符串数组转换为指定类型的数组
     * 
     * @param stringArray
     * @return
     */
    @SuppressWarnings("unchecked")
    public static <T> T[] getArray(String[] stringArray, Class<T> clazz) {
        int len = stringArray.length;
        T[] tArray = null;
        if ("Integer".equals(clazz.getSimpleName())) {
            Integer[] array = new Integer[len];
            for (int i = 0; i < len; i++) {
                array[i] = Integer.parseInt(stringArray[i]);
            }
            tArray = (T[]) array;
        } else if ("Long".equals(clazz.getSimpleName())) {
            Long[] array = new Long[len];
            for (int i = 0; i < len; i++) {
                array[i] = Long.parseLong(stringArray[i]);
            }
            tArray = (T[]) array;
        }
        return tArray;
    }

    /**
     * 刷新用户session资金信息
     * 
     * @param loginUser
     * @param request
     * @param userService
     * @return
     */
    public static Boolean refreshAccount(LoginUser loginUser, HttpServletRequest request, UserInfoService userService) {
        // QueryResult<Account> accountResult =
        // userService.queryAccount(loginUser.getMemberInfo().getBetCardNo());
        // if (CommUtil.isSuccess(accountResult))
        // {
        // List<Account> acounts = accountResult.getResults();
        // if (acounts != null && acounts.size() > 0)
        // {
        // loginUser.setAccount(acounts.get(0));
        // request.getSession().setAttribute(Constants.CLIENT_SESSION_MEMBER,
        // loginUser);// 保存资金session
        // return true;
        // }
        // }
        return false;
    }

    /**
     * 验签
     * 
     * @param signature
     * @return
     */
    public static String solSign(String signature) {
        // TODO Auto-generated method stub
        return signature;
    }

    /**
     * 是否为空
     * 
     * @param value
     * @return
     */
    public static boolean isNull(String value) {
        if (value == null || "".equals(value.trim())) {
            return true;
        }
        return false;
    }

    /**
     * <pre>
     * 判断某一对象是否为null
     * </pre>
     * 
     * 注意：<br/>
     * 1)集合、Map、数组还会判断长度是否为0，为0也认为是空<br/>
     * 2)空格字符串也认为是空<br/>
     * 
     * @param obj
     * @return
     */
    @SuppressWarnings("rawtypes")
    public static boolean isEmpty(Object obj) {
        if (obj == null) {
            return true;
        }
        if (obj instanceof String) {
            return (((String) obj).trim().length() == 0 ? true : false);
        }
        if (obj instanceof Collection) {
            return (((Collection) obj).size() == 0 ? true : false);
        }
        if (obj instanceof Map) {
            return (((Map) obj).size() == 0 ? true : false);
        }
        if (obj instanceof Object[]) {
            return (((Object[]) obj).length == 0 ? true : false);
        }
        return false;
    }

    /**
     * <pre>
     * 判断多个参数是否为null
     * </pre>
     * 
     * 注意：<br/>
     * 1)集合、Map、数组还会判断长度是否为0，为0也认为是空<br/>
     * 2)空格字符串也认为是空<br/>
     * 
     * @param obj
     * @return
     */
    public static boolean isEmptys(Object... obj) {
        if (obj == null) {
            return true;
        }
        for (Object object : obj) {
            if (isEmpty(object)) {
                return true;
            }
        }
        return false;
    }

    /**
     * 判断用户是否已经认证
     * 
     * @param userinfo
     *            用户信息
     * @return
     */
    public static boolean isAuthor(String cardNum) {
        // 判断用户是否认证，未认证跳转到认证页
        if (cardNum == null || "".equals(cardNum)) {
            return false;
        }
        return true;
    }

    /**
     * 判断用户是否有足够的余额，进行本次投注
     * 
     * @param account
     *            用户资金信息
     * @param betMoney
     *            本次投注额
     * @return
     */
    public static boolean isHaveEnoughMoney(Account account, int betMoney) {
        // // 余额判断，不足跳转到充值页面
        // if ((account.getBaseMoney() + account.getBonusMoney() +
        // account.getPresentMoney()) < betMoney)
        // {
        // return false;
        // }
        return true;
    }

    /**
     * 获取配置文件指定属性值
     * 
     * @param key
     *            属性名称
     * @return
     */
    public static String getProperyValue(String key) {
        if (cp == null) {
            synchronized (ConfigProvider.class) {
                if (cp == null) {
                    cp = ConfigProviderFactory.getInstance(Constant.HP_COMMON_PROPERTIES_FILEPATH);
                }
            }
        }
        return cp.getConfigByPrimaryKey(key);
    }

    /**
     * 获取会员店支持的玩法
     * 
     * @param request
     * @return
     */
    public static String getGameIds(HttpServletRequest request) {
        String key = "gameIds." + request.getServerName();
        String gameIds = getProperyValue(key);
        if (isEmpty(gameIds)) {
            gameIds = getProperyValue("gameIds");
        }
        return gameIds;
    }

    /**
     * 3D直选单复式拆分
     * 
     * @param hCode
     *            百位
     * @param tCode
     *            十位
     * @param sCode
     *            各位
     * @return
     */
    public static String directSplit(String[] hCode, String[] tCode, String[] sCode) {
        String codes = "";
        for (int h = 1, hlen = hCode.length; h < hlen; h++) {
            for (int t = 1, tlen = tCode.length; t < tlen; t++) {
                for (int s = 1, slen = sCode.length; s < slen; s++) {
                    codes += hCode[h] + "," + tCode[t] + "," + sCode[s] + ";";
                    // codesCount++;
                }
            }
        }
        return codes;
    }

    /**
     * 3D组3复式拆分
     * 
     * @param code
     *            组选号码
     * @return
     */
    public static String groupThreeSplit(String[] code) {
        String codes = "";
        for (int i = 1, ilen = code.length; i < ilen; i++) {
            for (int j = 1, jlen = code.length; j < jlen; j++) {
                if (i != j) {
                    codes += code[i] + "," + code[i] + "," + code[j] + ";";
                    // codesCount++;
                }
            }
        }
        return codes;
    }

    public static String groupThreeSplits(String[] code) {
        String codetijiao = "";
        int[] codepaixu = new int[code.length * (code.length - 1)];
        Integer count = 0;
        for (int i = 0, ilen = code.length; i < ilen; i++) {
            for (int j = 0, jlen = code.length; j < jlen; j++) {
                if (i != j) {
                    int[] a = { Integer.parseInt(code[i]), Integer.parseInt(code[j]), Integer.parseInt(code[j]) };
                    Arrays.sort(a); // 进行排序
                    String codes = "";
                    for (int k : a) {
                        codes += k;
                    }
                    codepaixu[count] = Integer.parseInt(codes);
                    count++;
                }
            }
        }
        Arrays.sort(codepaixu);
        for (int k : codepaixu) {
            String codes = "";
            // 因为排序的原因，整型004或044，排序后会变成4或44，所以投注号码不足三位前面补0
            String[] ab = String.format("%03d", k).split("");
            for (int i = 1; i < ab.length; i++) {
                codes += ab[i] + ",";
            }
            codetijiao += codes.substring(0, codes.length() - 1) + ";";
        }
        return codetijiao;
    }

    /**
     * 3D组6复式拆分
     * 
     * @param code
     * @return
     */
    public static String groupSixSplit(String[] code) {
        String codes = "";
        for (int h = 1, hlen = code.length - 2; h < hlen; h++) {
            for (int t = h + 1, tlen = code.length - 1; t < tlen; t++) {
                for (int s = t + 1, slen = code.length; s < slen; s++) {
                    codes += code[h] + "," + code[t] + "," + code[s] + ";";
                    // codesCount++;
                }
            }
        }
        return codes;
    }

    /**
     * 3D组6单式拆分
     * 
     * @param code
     * @return
     */
    public static String groupSixSplits(String[] code) {
        String codetijiao = "";
        for (int i = 0; i < code.length; i++) {
            for (int j = 0; j < code.length; j++) {
                for (int k = 0; k < code.length; k++) {
                    if (i < j && j < k && i < k) {
                        codetijiao += code[i] + "," + code[j] + "," + code[k] + ";";
                    }
                }
            }
        }
        return codetijiao;
    }

    /**
     * 3D直选和值拆分<br/>
     * 所有的组合都作为单注号码
     * 
     * @param code
     *            和值号码
     * @return
     */
    public static String directSumSplit(int code) {
        String codes = "";
        for (int h = 0; h < 10; h++) {
            for (int t = 0; t < 10; t++) {
                for (int s = 0; s < 10; s++) {
                    if ((h + t + s) == code) {
                        codes += h + "," + t + "," + s + ";";
                        // codesCount += 1;//统计注数
                    }
                    if (s > code)
                        break;// 大于和值，就没必要查找了
                }
                if (t > code)
                    break;
            }
            if (h > code)
                break;
        }
        return codes;
    }

    /**
     * 3D组选3和值拆分<br/>
     * 两个号码相同，有3个组合方式，为组3
     * 
     * @param code
     *            和值号码
     * @return
     */
    public static String groupThreeSumSplit(int code) {
        String codes = "";
        int t = 0;
        for (int h = 0; h < 10; h++) {
            t = h;
            for (int s = 0; s < 10; s++) {
                if (h != s && (h + t + s) == code) {
                    codes += h + "," + t + "," + s + ";";
                    // codesCount += 1;//统计注数
                    break;// 两两相同，第三位可以唯一确定该号码，查找到后，就可以结束此次循环
                }
                if (s > code)
                    break;// 大于和值，就没必要查找了
            }
            if (h > code)
                break;
        }
        return codes;
    }

    /**
     * 组选6和值拆分<br/>
     * 三个数各不相同，有6个组合方式，为组6
     * 
     * @param code
     *            和值号码
     * @return
     */
    public static String groupSixSumSplit(int code) {
        String codes = "";
        for (int h = 0; h < 8; h++) {
            for (int t = h + 1; t < 9; t++) {
                for (int s = t + 1; s < 10; s++) {
                    if ((h + t + s) == code) {
                        codes += h + "," + t + "," + s + ";";
                        // codesCount += 1;//统计注数
                    }
                    if (s > code)
                        break;// 大于和值，就没必要查找了
                }
                if (t > code)
                    break;
            }
            if (h > code)
                break;
        }
        return codes;
    }

    /**
     * 构造提交表单HTML数据, 默认POST
     * 
     * @param sParaTemp
     *            请求参数
     * @param gateway
     *            网关地址
     * @param strMethod
     *            提交方式。可选值：post、get、url
     * @param strButtonName
     *            确认按钮显示文字
     * @return 提交表单HTML文本
     */
    public static String buildForm(Map<String, String> sParaTemp, String gateway, String strMethod, String strButtonName) {
        String formHtml = "";
        if ("GET".equalsIgnoreCase(strMethod)) {
            // get TODO 暂未实现

        } else if ("URL".equalsIgnoreCase(strMethod)) {
            // 直接返回url
            String param = "?";
            try {
                param += mapToUrl(sParaTemp);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            formHtml = gateway + param;

        } else {
            // post
            StringBuffer sbHtml = new StringBuffer();
            sbHtml.append("页面正在跳转，请稍后...");
            sbHtml.append("<form id=\"express_submit\" name=\"express_submit\" action=\"" + gateway + "\" method=\""
                    + strMethod + "\">");
            for (Map.Entry<String, String> entry : sParaTemp.entrySet()) {
                String name = entry.getKey();
                String value = entry.getValue();
                sbHtml.append("<input type=\"hidden\" name=\"" + name + "\" value=\"" + value + "\"/>");
            }
            // submit按钮控件请不要含有name属性
            sbHtml.append("<input type=\"submit\" value=\"" + strButtonName + "\" style=\"display:none;\"></form>");
            sbHtml.append("<script>document.forms['express_submit'].submit();</script>");
            formHtml = sbHtml.toString();

        }
        return formHtml;
    }

    /**
     * 获取服务器当前url
     * 
     * @param request
     * @return
     */
    public static String getBasePath(HttpServletRequest request) {
        StringBuffer basePath = new StringBuffer();
        basePath.append(request.getScheme());
        basePath.append("://");
        basePath.append(request.getServerName());
        basePath.append(":");
        basePath.append(request.getServerPort());
        basePath.append(request.getContextPath());
        basePath.append("/");
        return basePath.toString();
    }

    /**
     * 转换参数值编码
     * 
     * @param params
     * @return
     */
    @SuppressWarnings("rawtypes")
    public static Map<String, String> convertCharset(Map<String, String[]> params) {
        Map<String, String> conParams = new HashMap<String, String>();
        for (Iterator iter = params.keySet().iterator(); iter.hasNext();) {
            String name = (String) iter.next();
            String[] values = (String[]) params.get(name);
            String valueStr = "";
            for (int i = 0; i < values.length; i++) {
                valueStr = (i == values.length - 1) ? valueStr + values[i] : valueStr + values[i] + ",";
            }
            // 乱码解决，这段代码在出现乱码时使用。如果mysign和sign不相等也可以使用这段代码转化
            try {
                valueStr = new String(valueStr.getBytes("ISO-8859-1"), "UTF-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            // logger.info(name + "=" + valueStr);
            conParams.put(name, valueStr);
        }
        return conParams;
    }

    /**
     * 获取登录用户session
     */
    public static LoginUser getLoinUser(HttpServletRequest request) {
        return (LoginUser) request.getSession().getAttribute(LSConstants.CLIENT_SESSION_MEMBER);
    }

    /**
     * 获取IP
     * 
     * @param request
     * @return
     */
    public static String getIp(HttpServletRequest request) {
        String ip = request.getHeader("x-forwarded-for");
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("WL-Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getRemoteAddr();
        }
        return ip;
    }

    /**
     * map转换成字符串
     * 
     * @param params
     * @return key1=value1;key2=value2;
     */
    public static String mapToString(Map<String, String> params) {
        StringBuilder sb = new StringBuilder();
        for (String key : params.keySet()) {
            String value = params.get(key);
            sb.append(key);
            sb.append("=");
            sb.append(value);
            sb.append(";");
        }
        return sb.toString();
    }

    /**
     * 将Map中的数据组装成url
     * 
     * @param params
     * @return
     * @throws UnsupportedEncodingException
     */
    public static String mapToUrl(Map<String, String> params) throws UnsupportedEncodingException {
        StringBuilder sb = new StringBuilder();
        boolean isFirst = true;
        for (String key : params.keySet()) {
            String value = params.get(key);
            if (isFirst) {
                sb.append(key + "=" + URLEncoder.encode(value, "utf-8"));
                isFirst = false;
            } else {
                if (value != null) {
                    sb.append("&" + key + "=" + URLEncoder.encode(value, "utf-8"));
                } else {
                    sb.append("&" + key + "=");
                }
            }
        }
        return sb.toString();
    }

    /**
     * 从属性文件根据key获取storeId
     * 
     * @param key
     * @return
     */
    public static String getStoreId(String key) {
        String storeId = CommUtil.getProperyValue(key);
        return isEmpty(storeId) ? "100" : storeId;
    }

    /**
     * 字符串分隔
     * 
     * @param content
     * @param parten
     * @return
     */
    public static String[] split(String content, String parten) {
        if (isEmpty(content)) {
            return null;
        }
        parten = isEmpty(parten) ? "," : parten;
        if (content.indexOf(parten) < 0) {
            return null;
        }
        return content.split(parten);
    }

    public static GsonBuilder createGson() {
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
            @Override
            public Date deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context)
                    throws JsonParseException {
                try {
                    SimpleDateFormat sdf = new SimpleDateFormat(CLIENT_REQUEST_DATETIME_PATTERN);
                    return sdf.parse(json.getAsString());
                } catch (ParseException e) {
                    throw new RuntimeException("日期{" + json.getAsString() + "}格式不对,Pattern应该为:"
                            + CLIENT_REQUEST_DATETIME_PATTERN, e);
                } catch (Exception e) {
                    throw new RuntimeException("日期转换错误{" + json.toString() + "}", e);
                }
            }
        });
        gsonBuilder.registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
            @Override
            public JsonElement serialize(Date arg0, Type arg1, JsonSerializationContext arg2) {
                SimpleDateFormat sdf = new SimpleDateFormat(CLIENT_REQUEST_DATETIME_PATTERN);
                return new JsonPrimitive(sdf.format(arg0));
            }
        });
        return gsonBuilder;
    }

    public static boolean validateObjectsNull(Object... obj) {
        if (obj == null)
            return true;
        for (Object o : obj) {
            if (o == null) {
                return true;
            }
        }
        return false;
    }

    /**
     * 获取指定范围随机数
     * 
     * @param max_ext
     * @param min_ext
     * @return
     */
    public static int getRandom(int max_ext, int min_ext) {
        Random random = new Random();
        int s = random.nextInt(max_ext) % (max_ext - min_ext + 1) + min_ext;
        return s;
    }
}
